package dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.shape;

public final class ExactShapeElement extends ShapeElement {
    public static ExactShapeElement create(int cardsCount, boolean validate) {
        if (validate) {
            if (cardsCount < 0 || cardsCount > 13) {
                throw new InvalidShapeElementException("cardsCount must be an integer between 0 and 13");
            }
        }
        return new ExactShapeElement(cardsCount);
    }

    private int cardsCount;

    ExactShapeElement() {
    }

    private ExactShapeElement(int cardsCount) {
        this.cardsCount = cardsCount;
    }

    public int getCardsCount() {
        return cardsCount;
    }

    public boolean match(int cardsCount) {
        return (this.cardsCount == cardsCount);
    }

    public String toString() {
        return String.valueOf(cardsCount);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ExactShapeElement that = (ExactShapeElement) o;
        return cardsCount == that.cardsCount;

    }

    @Override
    public int hashCode() {
        return cardsCount;
    }
}
